package spider

import (
	"database/sql"
	"fmt"
	_ "github.com/mattn/go-sqlite3"
)

var (
	db  *sql.DB // 数据库连接
	err error
)

func InsertData(sql string) error {
	tx, err := db.Begin()
	if err != nil {
		return err
	}

	_, err = tx.Exec(sql)
	if err != nil {
		return err
	}

	err = tx.Commit()
	return err
}

func init() {
	fmt.Println("init db")
	db, err = sql.Open("sqlite3", "./movies.db")
	if err != nil {
		fmt.Println("init db error", err)
	} else {
		fmt.Println("init db ok", db)
	}
}
